package com.xihuanjun.sdk.dao;

import com.fasterxml.jackson.core.type.TypeReference;
import com.xihuanjun.sdk.entity.JSTOut;
import com.xihuanjun.sdk.enums.JSTMethod;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

/**
 * Copyright (C), 2024-09-06
 * FileName: JSTOrderDao
 * Author:   溪浣君
 * Date:     2024-09-06 14:56
 * Description: 聚水潭订单操作，全部使用奇门
 */
@Component
public class JSTOrderDao extends BaseDao{


    /**
     * 根据线上单号查询所有订单信息，如果返回单据数超过20会抛异常
     * @param so_id
     * @return
     */
    public List<JSTOut> getOrderListBySoid(String so_id){
        HashMap<String,String> map=new HashMap<>();
        map.put("so_ids",so_id);
        map.put("page_index",1+"");
        map.put("page_size",20+"");

        List<JSTOut> jstOuts = null;
        try {
            jstOuts = this.qmListQuery(map, JSTMethod.QM_ORDER_LIST_QUERY, new TypeReference<List<JSTOut>>(){});
        } catch (IOException e) {
            e.printStackTrace();
        }
//        if(jstOuts!=null && jstOuts.size()==20){
//            throw new RuntimeException("查询订单号结果超出20");
//        }
        return jstOuts;
    }

    /**
     * 根据聚水潭内部单号查询一条订单
     * @param o_id 内部单号
     * @return
     */
    public JSTOut getOrderByOid(String o_id){
        HashMap<String,String> map=new HashMap<>();
        map.put("o_ids",o_id);
        map.put("page_index",1+"");
        map.put("page_size",20+"");

        List<JSTOut> jstOuts = null;
        try {
            jstOuts = this.qmListQuery(map, JSTMethod.QM_ORDER_LIST_QUERY,new TypeReference<List<JSTOut>>(){});
            return getOneFromList(jstOuts);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public List<JSTOut> getOrderListByShop(String shopId,String sendTime1,String sendTime2,int pageIndex,int pageSize){
        HashMap<String,String> map=new HashMap<>();
        map.put("shop_id",shopId);
        map.put("date_type","3");
        map.put("start_time",sendTime1);
        map.put("end_time",sendTime2);
        map.put("page_index",pageIndex+"");
        map.put("page_size",pageSize+"");

        List<JSTOut> jstOuts = null;
        try {
            jstOuts = this.qmListQuery(map, JSTMethod.QM_ORDER_LIST_QUERY, new TypeReference<List<JSTOut>>(){});
        } catch (IOException e) {
            e.printStackTrace();
        }
        return jstOuts;
    }
}
